** This do-file replicates tables 1 to 3 in 
** Pl�mper, Thomas and Eric Neumayer. 2010. The Level of Democracy during Interregnum Periods: Recoding the polity2 Score, Political Analysis, 18 (2)
** To replicate the results, save the data-file of the same name into your working directory and run this do-file

use "PA replication_tables 1 to 3.dta", clear

tsset ccode year
capture drop sample
gen sample=0
replace sample=1 if polity~=. & fhpr~=.

capture drop polity_hlp
gen polity_hlp=polity
replace polity_hlp=. if polity==-66
replace polity_hlp=. if polity==-77
replace polity_hlp=. if polity==-88
replace polity_hlp=. if sample==0

capture drop polity2_olog_hlp 
capture drop polity2olog_predict_hlp 
capture drop polity2olog_pred_det
capture drop t1-t21
ologit polity_hlp rgdpch rgdpch2 demshare500km devcountrycomlanguage  colsdummy   reg_eap  reg_eca  reg_mena  reg_sa  reg_we  reg_ssa    muslim
predict t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18  t19 t20 t21
gen polity2_olog_hlp=t1*-10+t2*-9+t3*-8+t4*-7+t5*-6+t6*-5+t7*-4+t8*-3+t9*-2+t10*-1+t12*1+t13*2+t14*3+t15*4+t16*5+t17*6+t18*7+t19*8+t20*9+t21*10
gen polity2olog_predict_hlp=round(polity2_olog_hlp)
gen polity2olog_pred_det=polity2olog_predict_hlp
replace polity2olog_pred_det=. if polity==-66 & year>=1972
replace polity2olog_pred_det=polity2 if polity==-88 & year>=1972 & interplusafftrans==0

capture drop polity2_olog_hlp 
capture drop polity2olog_predict_hlp 
capture drop polity2olog_pred_fh
capture drop t1-t21
ologit polity_hlp fhpr fhcl 
predict t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18  t19 t20 t21
gen polity2_olog_hlp=t1*-10+t2*-9+t3*-8+t4*-7+t5*-6+t6*-5+t7*-4+t8*-3+t9*-2+t10*-1+t12*1+t13*2+t14*3+t15*4+t16*5+t17*6+t18*7+t19*8+t20*9+t21*10
gen polity2olog_predict_hlp=round(polity2_olog_hlp)
gen polity2olog_pred_fh=polity2olog_predict_hlp
replace polity2olog_pred_fh=. if polity==-66 & year>=1972
replace polity2olog_pred_fh=polity2 if polity==-88 & year>=1972 & interplusafftrans==0

capture drop polity2_olog_hlp 
capture drop polity2olog_predict_hlp 
capture drop polity2olog_pred_all
capture drop t1-t21
ologit polity_hlp fhpr fhcl  rgdpch rgdpch2 demshare500km devcountrycomlanguage  colsdummy   reg_eap  reg_eca  reg_mena  reg_sa  reg_we  reg_ssa    muslim
predict t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18  t19 t20 t21
gen polity2_olog_hlp=t1*-10+t2*-9+t3*-8+t4*-7+t5*-6+t6*-5+t7*-4+t8*-3+t9*-2+t10*-1+t12*1+t13*2+t14*3+t15*4+t16*5+t17*6+t18*7+t19*8+t20*9+t21*10
gen polity2olog_predict_hlp=round(polity2_olog_hlp)
gen polity2olog_pred_all=polity2olog_predict_hlp
replace polity2olog_pred_all=. if polity==-66 & year>=1972
replace polity2olog_pred_all=polity2 if polity==-88 & year>=1972 & interplusafftrans==0

capture drop recode
gen recode=0
replace recode=1 if polity==-66
replace recode=1 if polity==-77
replace recode=1 if polity==-88

* table 1
corr polity2 polity2min polity2inter polity2max polity2olog_pred_det polity2olog_pred_fh polity2olog_pred_all 

* table 2
corr polity2 polity2olog_pred_det if recode==0
reg polity2 polity2olog_pred_det if recode==0

corr polity2 polity2olog_pred_fh if recode==0
reg polity2 polity2olog_pred_fh if recode==0

corr polity2 polity2olog_pred_all if recode==0
reg polity2 polity2olog_pred_all if recode==0

* table 3
corr polity2 polity2min polity2inter polity2max if interplusafftrans==1
reg polity2olog_pred_all polity2min if interplusafftrans==1
reg polity2olog_pred_all polity2max if interplusafftrans==1
reg polity2olog_pred_all polity2inter if interplusafftrans==1
